package export.monster
{
	import base.BaseMonster;
	
	import com.dusk.util.RandomUtil;
	import com.game.data.constant.AddEffectType;
	import com.game.data.constant.FrameRate;
	
	import com.game.engine.MainGame;
	import com.game.event.GameEventType;
	
	import com.game.manager.AnimationManager;
	import com.game.manager.EventManager;
	
	import export.bullet.EnemyMoveBullet;
	import export.bullet.FollowTargetBullet;
	
	import export.bullet.RegionBullet;
	import export.level.StageListener21;
	
	import flash.geom.Rectangle;
	//狮驼王
	public class Monster206 extends BaseMonster
	{
		public function Monster206()
		{
			super();
		}
		
		override protected function initAttribute():void
		{
			super.initAttribute();
			mavo.attackRange = 110;
			if(MainGame.getIns().levelData.levelID == "2_2")
			{
				if(gc.pWorld.getBaseLevelListener() as StageListener21 != null)
				{
					if((gc.pWorld.getBaseLevelListener() as StageListener21)["hurtTimes"] > 5)
					{
						mavo.hpMax *= 2;
						setFullHp();
					}
				}
			}
		}
		
		override protected function initBBDC():void
		{
			bbdc = AnimationManager.getAnimation("Monster206Action");
			bbdc.setAction("idle");
			bbdc.turnRight();
			bbdc.addCallBack(onEnterFrame, onActionOver);
			bodyContainer.addChild(bbdc);
		}
		
		override protected function initCollideArea():void
		{
			collideBox = new Rectangle(-21,-81,46,82);
			super.initCollideArea();
		}
		
		override protected function onEnterFrame(action:String, frameCount:int):void
		{
			switch (action)
			{
				case "attack1":
					if(frameCount == 3)
					{
						var b:RegionBullet = new RegionBullet();
						b.setOwner(this);
						b.setDirect(bbdc.getDirect());
						b.setCollideArea(-7,-100,112 * bbdc.getDirect(),200);
						b.setHurt(getActionHurt("attack1"));
						b.setDestroyInCount(9);
						b.setAction("Monster206Attack1");
						gc.gameScene.addChild(b);
						magicBulletArray.push(b);
					}
					break;
				case "skill1":
					if(frameCount == 26)
					{
						var bu1:EnemyMoveBullet = new EnemyMoveBullet("Monster206Skill1");
						bu1.setClipOffset(0,-40);
						bu1.setOwner(this);
						bu1.setPosition(getCollideCenter().x - 200,getCollideCenter().y);
						bu1.setHurt(getActionHurt("skill1"));
						bu1.setAction("Monster206Skill1");
						bu1.setDirect(bbdc.getDirect());
						bu1.setSpeed(0,0);
						bu1.setIsDestroyWhenLastFrame(true);
						gc.gameScene.addChild(bu1);
						magicBulletArray.push(bu1);
					}
					if(frameCount == 27)
					{
						var bu2:EnemyMoveBullet = new EnemyMoveBullet("Monster206Skill1");
						bu2.setClipOffset(0,-40);
						bu2.setOwner(this);
						bu2.setPosition(getCollideCenter().x + 200,getCollideCenter().y);
						bu2.setHurt(getActionHurt("skill1"));
						bu2.setAction("Monster206Skill1");
						bu2.setDirect(bbdc.getDirect());
						bu2.setSpeed(0,0);
						bu2.setIsDestroyWhenLastFrame(true);
						gc.gameScene.addChild(bu2);
						magicBulletArray.push(bu2);
					}
					break;
				case "skill2":
					if(frameCount == 7)
					{
						setSteelBody(bbdc.frameLeft);
						var s:FollowTargetBullet = new FollowTargetBullet("Monster206Skill2");
						s.setOwner(this);
						s.setCollideArea(-170,-50,339,55);
						s.setHurt(getActionHurt("skill2"));
						s.setAction("Monster206Skill2");
						s.hitVO.addEffect = [{
							type: AddEffectType.POISON,
							frame: FrameRate.ANIMATE_FRAME_RATE * 5,
							value: mavo.atk
						}];
						gc.gameScene.addChild(s);
						magicBulletArray.push(s);
					}
			}
		}
		
		override protected function beforeSkill1Start():Boolean
		{
			return hasTarget() && AUtils.GetDisBetweenTwoObj(this,curAttackTarget) < 400;
		}
		
		override protected function releSkill1():void
		{
			//巨石破
			for (var i:int = 0; i < 3; i++)
			{
				EventManager.getIns().dispatchEvent(GameEventType.CREATE_MONSTER,
						{type:RandomUtil.randSwitch([202,203]),
							x:RandomUtil.randInt(x - 200,x + 200),
							y:RandomUtil.randInt(y - 200,y)});
			}
			super.releSkill1();
		}
		
		override protected function beforeSkill2Start():Boolean
		{
			//毒坛
			return hasTarget() && AUtils.GetDisBetweenTwoObj(this,curAttackTarget) < 400;
		}
	}
}